package beusoft.ccjk.com.plugin

import android.app.Activity
import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import android.view.View

/**
 * Created by CCJK on 2017/12/1.
 */
open class BaseActivity : AppCompatActivity() {
    lateinit var proxyActivity: Activity

    companion object {
        val FROM = "FROM"
        val INTERNAL = 1
        val EXTERNAL = 2
    }

    private var from = INTERNAL

    fun setProxy(activity: Activity) {
        proxyActivity = activity
    }

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        savedInstanceState?.let {
            from = it.getInt(FROM, INTERNAL)
        }
        if (from == INTERNAL) {
            super.onCreate(savedInstanceState)
            proxyActivity = this
        }
    }

    override fun setContentView(view: View?) {
        if (from == INTERNAL) {
            super.setContentView(view)
        } else proxyActivity.setContentView(view)
    }

}